package com.tianyu.inspection.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tianyu.inspection.common.Constants;
import com.tianyu.inspection.common.HttpRequest;
import com.tianyu.inspection.common.annotation.Permission;
import com.tianyu.inspection.common.component.AppConstants;
import com.tianyu.inspection.common.component.Validate;
import com.tianyu.inspection.common.enums.FileTypeEnum;
import com.tianyu.inspection.common.enums.RoState;
import com.tianyu.inspection.common.model.JedisModel;
import com.tianyu.inspection.entity.Project;
import com.tianyu.inspection.entity.model.OperateMo;
import com.tianyu.inspection.entity.model.QueryMo;
import com.tianyu.inspection.entity.vo.Ro;
import com.tianyu.inspection.entity.vo.ServiceRo;
import com.tianyu.inspection.mapper.*;
import com.tianyu.inspection.service.api.IProjectService;
import com.tianyu.inspection.service.telemetry.yukong.YkClient;
import com.tianyu.inspection.service.websocket.TelemetryQueue;
import com.tianyu.inspection.service.websocket.WebSocketService;
;
import io.netty.channel.Channel;
import io.ocs.model.OcsSimpleModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;

import static com.tianyu.inspection.service.telemetry.yukong.YkClient.YK_CHANNEL_MAP;

/**********************************
 * @Author YSW
 * @Description 项目接口
 * @Date 2021/1/6 - 18:33
 **********************************/

@Slf4j
@RestController
@RequestMapping("/api/2.0/project/admin")
public class ProjectController {

    @Resource
    private IProjectService projectService;

    @Resource
    private Validate validateModel;

    @Resource
    private PipelineMapper pipelineMapper;

    @Resource
    private InfrastructureTypeMapper infrastructureTypeMapper;

    @Resource
    private ConstructionTypeMapper constructionTypeMapper;

    @Resource
    private GeneralFacilitiesTypeMapper generalFacilitiesTypeMapper;

    @Resource
    private HighConsequenceAreasTypeMapper highConsequenceAreasTypeMapper;

    @Resource
    private PileCardTypeMapper pileCardTypeMapper;

    @Resource
    private CameraTypeMapper cameraTypeMapper;

    @Resource
    private DangerTypeMapper dangerTypeMapper;

    @Resource
    private AppConstants appConstants;

    @Resource
    private WebSocketService webSocketService;

    @Resource
    private FlyTaskMapper flyTaskMapper;

    @Resource
    private UploadFileMapper uploadFileMapper;

    @Resource
    private OcsSimpleModel ocsSimpleModel;

    @Resource
    private JedisModel jedisModel;

    /**
     * 获取项目列表
     *
     * @param request 请求
     * @return
     */
    @GetMapping(value = "/list")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<IPage<Project>> getPageList(HttpServletRequest request) {
        QueryMo queryMo = QueryMo.getQueryMo(request);
        Ro<IPage<Project>> ro = new Ro<>();
        queryMo.build(Project.class, null);
        if (Objects.nonNull(queryMo.get("state"))) {
            queryMo.getEqMap().put("state", queryMo.get("state"));
        } else {
            queryMo.getEqMap().remove("state");
        }
        return ro.setContent(projectService.searchListPage(queryMo));
    }

    @GetMapping(value = "/{id}")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<Project> getOne(@PathVariable Integer id) {
        Ro<Project> ro = new Ro<>();
        if (Objects.isNull(id)) {
            return ro.setResultEnum(RoState.PARAMS_MISS_ERROR);
        }
        QueryMo queryMo = new QueryMo();
        queryMo.put("id", id);
        queryMo.build(Project.class, null);
        if (Objects.nonNull(queryMo.get("state"))) {
            queryMo.getEqMap().put("state", queryMo.get("state"));
        } else {
            queryMo.getEqMap().remove("state");
        }
        Project project = projectService.selectOne(queryMo);
        if (Objects.isNull(project)) {
            ro.setMessage("未查询到数据");
        } else {
            ro.setContent(project);
        }
        return ro;
    }

    /**
     * 创建新项目
     *
     * @param operateMo
     * @return
     */
    @PostMapping(value = "/insert")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<Project> insert(@RequestBody OperateMo operateMo) {
        Ro<Project> ro = new Ro<>();
        operateMo.createBuild(Project.class, null);
        if (operateMo.getEntity().size() == 0) {
            return ro.setResultEnum(RoState.FAIL).setMessage("无操作参数传入,请传参后重试");
        }
        if (Objects.nonNull(operateMo.get("clientLogo"))) {
            if (validateModel.uploadImageValidate(FileTypeEnum.FILE_CLIENT_IMG.getValue(), operateMo.get("clientLogo").toString())) {
                return ro.setMessage("参数错误[clientLogo],文件不存在或类别有误");
            }
        }
        if (!projectService.insert(operateMo)) {
            ro.setResultEnum(RoState.FAIL);
        }
        return ro;
    }

    /**
     * 项目更新
     *
     * @param operateMo 操作参数
     * @return
     */
    @PatchMapping(value = "/modify")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<Void> modify(@RequestBody OperateMo operateMo) {
        OperateMo operateMo1 = new OperateMo();
        operateMo1.put("id", operateMo.get("id"));
        operateMo1.put("projectName", operateMo.get("projectName"));
        operateMo1.put("clientModule", operateMo.get("clientModule"));
        operateMo1.put("clientName", operateMo.get("clientName"));
        operateMo1.put("clientLogo", operateMo.get("clientLogo"));
        final ServiceRo serviceRo = operateMo1.updateBuild(Project.class, null);
        if (!serviceRo.getResult()) {
            return new Ro<Void>().setResultEnum(RoState.FAIL).setMessage(serviceRo.getMessage());
        }
        if (Objects.isNull(operateMo1.get("id"))) {
            return new Ro<Void>().setResultEnum(RoState.FAIL).setMessage("缺少[id]字段,请传参后重试");
        }
        if (Objects.nonNull(operateMo1.get("state"))) {
            operateMo1.getEqMap().put("state", operateMo1.get("state"));
        } else {
            operateMo1.getEqMap().remove("state");
        }
        Project project = new ObjectMapper().convertValue(operateMo1.getEntity(), Project.class);
        if (Objects.nonNull(project.getClientLogo())) {
            if (validateModel.uploadImageValidate(FileTypeEnum.FILE_CLIENT_IMG.getValue(), project.getClientLogo())) {
                return new Ro<Void>().setMessage("参数错误[clientLogo],文件不存在或类别有误");
            }
        }
        if (Objects.nonNull(project.getClientModule())) {
            try {
                ObjectMapper objectMapper = new ObjectMapper();
                JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, Integer.class);
                ArrayList<Integer> jsonArray = objectMapper.readValue(project.getClientModule(), javaType);
                if (!Arrays.asList(0, 1).containsAll(jsonArray)) {
                    return new Ro<Void>().setResultEnum(RoState.FAIL).setMessage("参数错误[clientModule],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Void>().setResultEnum(RoState.FAIL).setMessage("参数错误[clientModule],数组字符串解析异常");
            }
        }
        if (!projectService.update(operateMo1)) {
            new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数无匹配,修改失败");
        }
        return new Ro<>();
    }

    /**
     * 险情及基础信息类型选择
     *
     * @param operateMo 操作参数
     * @return
     */
    @PostMapping(value = "/typeSelect")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<Project> typeSelect(@RequestBody OperateMo operateMo) {
        OperateMo operateMo1 = new OperateMo();
        operateMo1.put("id", operateMo.get("id"));
        operateMo1.put("dangerTypeUse", operateMo.get("dangerTypeUse"));
        operateMo1.put("pileCardTypeUse", operateMo.get("pileCardTypeUse"));
        operateMo1.put("constructionTypeUse", operateMo.get("constructionTypeUse"));
        operateMo1.put("highConsequenceAreaTypeUse", operateMo.get("highConsequenceAreaTypeUse"));
        operateMo1.put("generalFacilitiesTypeUse", operateMo.get("generalFacilitiesTypeUse"));
        operateMo1.put("cameraTypeUse", operateMo.get("cameraTypeUse"));
        operateMo1.put("infrastructureTypeUse", operateMo.get("infrastructureTypeUse"));
        operateMo1.updateBuild(Project.class, null);
        if (operateMo1.getEntity().size() == 0) {
            return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("请传入要修改的参数");
        }
        if (Objects.isNull(operateMo1.get("id"))) {
            return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("缺少[id]字段,请传参后重试");
        }
        if (Objects.nonNull(operateMo1.get("state"))) {
            operateMo1.getEqMap().put("state", operateMo1.get("state"));
        } else {
            operateMo1.getEqMap().remove("state");
        }
        Project project = new ObjectMapper().convertValue(operateMo1.getEntity(), Project.class);
        if (Objects.nonNull(project.getInfrastructureTypeUse())) {
            try {
                if (validateModel.validateIdArray(infrastructureTypeMapper, project.getInfrastructureTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[infrastructureTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[infrastructureTypeUse],数组字符串解析异常");
            }
        }
        if (Objects.nonNull(project.getConstructionTypeUse())) {
            try {
                if (validateModel.validateIdArray(constructionTypeMapper, project.getConstructionTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[constructionTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[constructionTypeUse],数组字符串解析异常");
            }
        }
        if (Objects.nonNull(project.getGeneralFacilitiesTypeUse())) {
            try {
                if (validateModel.validateIdArray(generalFacilitiesTypeMapper, project.getGeneralFacilitiesTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[valueChestTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[valueChestTypeUse],数组字符串解析异常");
            }
        }
        if (Objects.nonNull(project.getHighConsequenceAreaTypeUse())) {
            try {
                if (validateModel.validateIdArray(highConsequenceAreasTypeMapper, project.getHighConsequenceAreaTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[highConsequenceAreaTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[highConsequenceAreaTypeUse],数组字符串解析异常");
            }
        }
        if (Objects.nonNull(project.getPileCardTypeUse())) {
            try {
                if (validateModel.validateIdArray(pileCardTypeMapper, project.getPileCardTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[pileCardTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[pileCardTypeUse],数组字符串解析异常");
            }
        }
        if (Objects.nonNull(project.getCameraTypeUse())) {
            try {
                if (validateModel.validateIdArray(cameraTypeMapper, project.getCameraTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[cameraTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[cameraTypeUse],数组字符串解析异常");
            }
        }
        if (Objects.nonNull(project.getDangerTypeUse())) {
            try {
                if (validateModel.validateIdArray(dangerTypeMapper, project.getDangerTypeUse())) {
                    return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[dangerTypeUse],数组字符串值异常");
                }
            } catch (Exception e) {
                return new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数错误[dangerTypeUse],数组字符串解析异常");
            }
        }
        if (!projectService.update(operateMo1)) {
            new Ro<Project>().setResultEnum(RoState.FAIL).setMessage("参数无匹配,修改失败");
        }
        return new Ro<>();
    }

    /**
     * 御空接入
     *
     * @param operateMo 操作参数
     * @return
     */
    @PostMapping(value = "/yuKongAccount/access")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public synchronized Ro<Void> yuKongAccountAccess(@RequestBody OperateMo operateMo) {
        Ro<Void> ro = new Ro<>();
        Integer projectId = (Integer) operateMo.get("projectId");
        String ykAccessKey = (String) operateMo.get("ykAccessKey");
        String ykAccessSecret = (String) operateMo.get("ykAccessSecret");
        if (Objects.isNull(operateMo.get("projectId"))) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少[projectId]字段,请传参后重试");
        } else {
            if (Objects.nonNull(YK_CHANNEL_MAP.get(projectId))) {
                return ro.setResultEnum(RoState.FAIL).setMessage("已存在正在运行的御空账户,请在关闭该账户后重新操作");
            }
        }
        if (Objects.isNull(ykAccessKey)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[ykAccessKey]");
        }
        if (Objects.isNull(ykAccessSecret)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[ykAccessSecret]");
        }
        QueryMo queryMo = new QueryMo();
        queryMo.put("ykAccessKey", ykAccessKey);
        queryMo.build(Project.class, null);
        queryMo.getEqMap().remove("state");
        if (0 != projectService.selectCount(queryMo)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空账户已在项目存在,接入失败");
        }
        if (validateModel.validateYkAccount(ykAccessKey, ykAccessSecret)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("校验失败");
        }
        OperateMo operateMo1 = new OperateMo();
        operateMo1.put("id", projectId);
        operateMo1.put("ykAccessKey", ykAccessKey);
        operateMo1.put("ykAccessSecret", ykAccessSecret);
        operateMo1.updateBuild(Project.class, null);
        operateMo1.getEqMap().remove("state");
        operateMo1.getEntity().put("ykAccessAvailable", 0);
        if (!projectService.update(operateMo1)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空接入失败");
        }
        QueryMo queryMo1 = new QueryMo();
        queryMo1.putAll(operateMo1);
        queryMo1.build(Project.class, null);
        if (1 == projectService.selectCount(queryMo1)) {
            Constants.EXECUTOR.execute(() -> new YkClient(
                    false,
                    projectId,
                    ykAccessKey,
                    ykAccessSecret,
                    webSocketService,
                    flyTaskMapper,
                    pipelineMapper,
                    uploadFileMapper,
                    projectService,
                    ocsSimpleModel,
                    jedisModel,
                    appConstants)
            );
            log.info("Project[" + projectId + "] 御空 Service Access Start...");
            return ro.setMessage("御空接入成功!");
        } else {
            return ro.setMessage("御空接入成功,项目当前状态不可用,切换可用状态可接入御空数据");
        }
    }

    /**
     * 开启御空账户
     *
     * @param operateMo 操作参数
     * @return
     */
    @PostMapping(value = "/yuKongAccount/start")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public synchronized Ro<Void> yuKongAccountStart(@RequestBody OperateMo operateMo) {
        Ro<Void> ro = new Ro<>();
        Integer projectId = (Integer) operateMo.get("projectId");
        if (Objects.isNull(projectId)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[projectId]");
        } else {
            if (validateModel.projectIdValidate(projectId)) {
                return ro.setResultEnum(RoState.FAIL).setMessage("参数错误[projectId],值不存在");
            }
        }
        String ykAccessKey = (String) operateMo.get("ykAccessKey");
        String ykAccessSecret = (String) operateMo.get("ykAccessSecret");
        if (Objects.isNull(ykAccessKey)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[ykAccessKey]");
        }
        if (Objects.isNull(ykAccessSecret)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[ykAccessSecret]");
        }
        QueryMo queryMo = new QueryMo();
        queryMo.put("id", operateMo.get("projectId"));
        queryMo.build(Project.class, null);
        if (0 == projectService.selectCount(queryMo)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("项目[" + projectId + "]账户状态不可用,切换可用状态可开启接入御空数据");
        }
        queryMo.getEqMap().put("yk_access_key", ykAccessKey);
        queryMo.getEqMap().put("yk_access_secret", ykAccessSecret);
        Project project = projectService.selectOne(queryMo);
        if (Objects.isNull(project)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空账户参数错误[ykAccessKey|ykAccessSecret]");
        } else {
            if (project.getYkAccessAvailable() == 0 && Objects.nonNull(YK_CHANNEL_MAP.get(projectId))) {
                return ro.setResultEnum(RoState.FAIL).setMessage("御空Tcp接遥测已在开启状态,不可重复开启");
            }
        }

        if (validateModel.validateYkAccount(ykAccessKey, ykAccessSecret)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空账户校验失败,参数错误[ykAccessKey|ykAccessSecret]");
        } else {
            if (Objects.nonNull(YK_CHANNEL_MAP.get(projectId))) {
                return ro.setResultEnum(RoState.FAIL).setMessage("御空Tcp接遥测已在开启状态,不可重复开启");
            }
            Constants.EXECUTOR.execute(() -> new YkClient(
                    false,
                    projectId,
                    ykAccessKey,
                    ykAccessSecret,
                    webSocketService,
                    flyTaskMapper,
                    pipelineMapper,
                    uploadFileMapper,
                    projectService,
                    ocsSimpleModel,
                    jedisModel,
                    appConstants)
            );
            log.info("Project[" + projectId + "] 御空 Service Access Start...");
            OperateMo operateMo1 = new OperateMo();
            operateMo1.put("id", projectId);
            operateMo1.put("ykAccessAvailable", 0);
            operateMo1.updateBuild(Project.class, null);
            projectService.update(operateMo1);
            return ro.setMessage("开启接入御空数据成功");
        }
    }

    /**
     * 御空关闭
     *
     * @param operateMo 操作参数
     * @return 关闭结果反馈
     */
    @PostMapping(value = "/yuKongAccount/shutdown")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public synchronized Ro<Void> yuKongAccountShutdown(@RequestBody OperateMo operateMo) {
        Ro<Void> ro = new Ro<>();
        Integer projectId = (Integer) operateMo.get("projectId");
        if (Objects.isNull(projectId)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[projectId]");
        } else {
            if (validateModel.projectIdValidate(projectId)) {
                return ro.setResultEnum(RoState.FAIL).setMessage("参数错误[projectId],值不存在");
            }
        }
        String ykAccessKey = (String) operateMo.get("ykAccessKey");
        String ykAccessSecret = (String) operateMo.get("ykAccessSecret");
        if (Objects.isNull(ykAccessKey)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[ykAccessKey]");
        }
        if (Objects.isNull(ykAccessSecret)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("缺少参数[ykAccessSecret]");
        }
        QueryMo queryMo = new QueryMo();
        queryMo.put("id", operateMo.get("projectId"));
        queryMo.build(Project.class, null);
        if (0 == projectService.selectCount(queryMo)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("项目[" + projectId + "]账户状态不可用,操作失败");
        }
        queryMo.getEqMap().put("yk_access_key", ykAccessKey);
        queryMo.getEqMap().put("yk_access_secret", ykAccessSecret);
        Project project = projectService.selectOne(queryMo);
        if (Objects.isNull(project)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空账户参数错误[ykAccessKey|ykAccessSecret]");
        }
        Channel channel = YK_CHANNEL_MAP.get(projectId);
        if (channel == null || !channel.isOpen()) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空Tcp接遥测未在开启状态");
        }
        channel.close();
        if (validateModel.validateYkAccount(ykAccessKey, ykAccessSecret)) {
            return ro.setResultEnum(RoState.FAIL).setMessage("御空账户校验失败,参数错误[ykAccessKey|ykAccessSecret]");
        }
        ModelMap login = HttpRequest.yuKongThirdLogin(appConstants.yuKongHttpHost, ykAccessKey, ykAccessSecret);
        if (login.get("state").equals(1)) {
            YK_CHANNEL_MAP.remove(projectId);
        } else {
            return ro.setResultEnum(RoState.FAIL);
        }
        TelemetryQueue.telemetryQueueMap.keySet().stream().filter(item -> item.startsWith(projectId.toString())).forEach(item -> {
            String[] values = item.split("-&-");
            if ("yuKong".equals(values[1])) {
                TelemetryQueue.telemetryQueueMap.remove(item);
                jedisModel.del(appConstants.redisTelemetry + values[0] + ":yuKong:" + values[2]);
                log.debug("项目[" + values[0] + "] 实时遥测队列[" + item + "]已销毁, 御空飞行任务[" + values[2] + "]缓存遥测已删除...");
            }
        });

        OperateMo operateMo1 = new OperateMo();
        operateMo1.put("id", projectId);
        operateMo1.put("ykAccessAvailable", 1);
        operateMo1.updateBuild(Project.class, null);
        projectService.update(operateMo1);
        return ro.setMessage("御空Tcp接遥测关闭成功,该账户御空账户已置为不可用状态");
    }

    @DeleteMapping(value = "/delete/{id}")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<Project> delete(@PathVariable Integer id) {
        Ro<Project> ro = new Ro<>();
        QueryMo queryMo = new QueryMo();
        queryMo.put("id", id);
        queryMo.build(Project.class, null);
        queryMo.getEqMap().remove("state");
        if (!projectService.delete(queryMo)) {
            ro.setResultEnum(RoState.FAIL).setMessage("无匹配ID,删除失败");
        }
        return ro;
    }

    @DeleteMapping(value = "/delete/logical/{id}")
    @Permission(value = 1, tags = Constants.API_SUPER)
    public Ro<Project> logicallyDelete(@PathVariable Integer id) {
        Ro<Project> ro = new Ro<>();
        QueryMo queryMo = new QueryMo();
        queryMo.put("id", id);
        queryMo.build(Project.class, null);
        if (!projectService.logicallyDelete(queryMo)) {
            ro.setResultEnum(RoState.FAIL).setMessage("无匹配ID,删除失败");
        }
        return ro;
    }

    /**
     * 御空账户校验
     *
     * @param queryMo 查询参数
     * @return 是否校验成功
     */
    @PostMapping(value = "/validateYkAccount")
    @Permission(value = 1, tags = Constants.API_SUPER)
    private Ro<Void> validateYuKongAccount(@RequestBody QueryMo queryMo) {
        Ro<Void> ro = new Ro<>();
        boolean result = validateModel.validateYkAccount((String) queryMo.get("ykAccessKey"), (String) queryMo.get("ykAccessSecret"));
        return result ? ro.setResultEnum(RoState.FAIL).setMessage("校验失败") : ro.setMessage("校验成功");
    }

}